/*
 * Singularity Engine
 * Copyright (C) 2010 Vyacheslav Vorobyov, All rights reserved.
 * See LICENSE for full license information.
 */

/**
 * 
 */
package org.singularity.mapred.model;

import java.util.Set;

import org.singularity.mapred.Element;

/**
 * @author vjache
 *
 */
public abstract class AbstractElement implements Element {

	protected final DefaultCascade _cascade;
	private final Object _id;
	private final Code _elCode;

	protected AbstractElement(DefaultCascade aCascade, Element.Code aElemCode, Object aId)
	{
		_cascade = aCascade;
		_id = aId;
		_elCode = aElemCode;
	}

	/* (non-Javadoc)
	 * @see org.singularity.mapred.ver2.Element#getCascade()
	 */
	@Override
	public DefaultCascade getCascade() {
		return _cascade;
	}
	
	public Set<Flow> outflows()
	{
		return _cascade.outflows(this);
	}
	
	public Set<Flow> inflows()
	{
		return _cascade.inflows(this);
	}

	/**
	 * @return the id
	 */
	public Object getId() {
		return _id;
	}

	/**
	 * @return the elCode
	 */
	public Code getElementCode() {
		return _elCode;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("{");
		sb.append(" id:");
		sb.append(_id);
		sb.append(",");
		sb.append(" code:");
		sb.append(_elCode);
		sb.append("}");
		return sb.toString();
	}

}
